#!/bin/bash
# PNGTOMPEG CONVERSION SCRIPT
# USGAE : pngtompeg <PROJECT_NAME> <PROJECT_PATH>
# ----------------------------------------------------


pname=$1
pdir=$2
menbin=`which mencoder`

if [ -z $pname ]; then
    echo "USAGE: $0 <PROJECT_NAME> <PROJECT_PATH>"
    exit -1;
fi

if [ -z $pdir ]; then
    echo "USAGE: $0 <PROJECT_NAME> <PROJECT_PATH>"
    exit -1;
fi

if[ -z $menbin ]; then
    echo "ERROR : COULD NOT FIND MENCODER BINARY"
    echo "...PLEASE INSTALL MPLAYER"
    exit -1;
fi

#-- GET NUMBER OF PNGS
numpng=`ls -l $pdir/ | grep png | grep $pname | count -l`

echo "....FOUND $numpng PNGS"
echo "....CONVERTING..."

$MENBIN -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1500 -vf scale=640x480 -mf type=png:fps=20 -nosound -of mpeg -o $pdir/$pname.mpg mf://$pdir/$pname*.png

echo "....DONE!"
echo "....SEE $pdir/$pname.mpeg"

echo "PNGTOMPEG v0.1"

exit 0;